﻿using CmsIdentity.Services;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity.Data;
using Microsoft.AspNetCore.Mvc;

namespace CmsIdentity.Controllers
{
  [ApiController]
  [Route("api/auth/token")]
  public class AuthController : ControllerBase
  {
    private readonly JwtTokenService _jwtTokenService;

    public AuthController(JwtTokenService jwtTokenService)
    {
      _jwtTokenService = jwtTokenService;
    }

    [HttpPost]
    public IActionResult Login([FromBody] LoginRequest request)
    {
      // 模拟用户登录逻辑
      if (request.Username == "admin" && request.Password == "password")
      {
        var token = _jwtTokenService.GenerateToken("1", "admin", "Admin");
        return Ok(new { token });
      }

      return Unauthorized();
    }
  }

  public class LoginRequest
  {
      public required string Username { get; set; }
      public required string Password { get; set; }
  }
}
